//
//  HotCountryCollectionViewCell.m
//  Journey
//
//  Created by dllo on 16/5/18.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "HotCountryCollectionViewCell.h"
#import "UIImageView+WebCache.h"
@implementation HotCountryCollectionViewCell

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createHotCountry];
    }
    return self;
}

-(void)createHotCountry
{
    self.photo = [[UIImageView alloc] init];
    self.photo.backgroundColor = [UIColor yellowColor];
    [self.contentView addSubview:self.photo];
    self.cnname = [[UILabel alloc] init];
    self.cnname.textColor = [UIColor whiteColor];
    self.cnname.backgroundColor = [UIColor blackColor];
    self.cnname.alpha = 0.5;
    [self.contentView addSubview:self.cnname];
    self.count = [[UILabel alloc]init];
    self.count.textColor = [UIColor whiteColor];
    self.count.backgroundColor = [UIColor blackColor];
    self.count.alpha = 0.3;
    [self.contentView addSubview:self.count];
}


-(void)layoutSubviews{
    [super layoutSubviews];
    self.photo.frame = self.contentView.bounds;
   
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:17],NSFontAttributeName, nil];
    CGRect rect = [self.cnname.text boundingRectWithSize:CGSizeMake(0, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    
     self.cnname.frame = CGRectMake(self.photo.frame.size.width - 80, self.photo.frame.origin.y + 10, rect.size.width, rect.size.height);
    
    self.cnname.numberOfLines = 2;
    
    self.count.frame = CGRectMake(self.photo.frame.origin.x , self.photo.frame.size.height - 80, self.contentView.frame.size.width, 80 * WIDTHC);
    self.count.numberOfLines = 2;
}

-(void)setHotCountry:(hotCountryModel *)hotCountry{
    _hotCountry = hotCountry;
    [self.photo sd_setImageWithURL:[NSURL URLWithString:_hotCountry.photo] placeholderImage:[UIImage imageNamed:@"image2"]];
    self.count.text =[NSString stringWithFormat:@"%@\n%@",_hotCountry.cnname,_hotCountry.enname];
    self.cnname.text = [NSString stringWithFormat:@"%@\n   %@",[_hotCountry.count stringValue],_hotCountry.label ];
   
   
      
}


@end
